/*
 * 计算目录大小
 */

var fs = require('fs');

var dir = process.argv[2] || 'D:/梦瑶视频/';

var size = 0;

var files = fs.readdirSync(dir);

for (i in files) {
    size += fs.statSync(dir + files[i]).size;
}

console.log('目录：' + dir);

var byte = 0;
var unit = 'B';
if (size > 1024 * 1024 * 1024) {
    byte = size / 1024 / 1024 / 1024;
    unit = 'GB';
} else if (size > 1024 * 1024) {
    byte = size / 1024 / 1024;
    unit = 'MB';
} else if (size > 1024) {
    byte = size / 1024;
    unit = 'KB';
}

console.log('大小：' + byte.toFixed(2) + unit + '(' + size + '字节)');
